<template>
    <div class="listDiv mt10">
        <div class="searchDiv">
            <el-select v-model="obj.req.state" placeholder="全部状态" class="search_select" clearable>
                <el-option v-for="(item,index) in globalData.verifyTypeAry2" :key="index" :label="item.text" :value="item.value" />
            </el-select>
            <el-input clearable placeholder="匹配机构名称" v-model="obj.req.key" class="search_key" />
            <span class="btn search" @click="init">搜索</span>
            <span class="btn refresh" @click="obj.req.currentpage=1;init()"></span>
            <div class="searchRight">
                <span class="btn add" @click="add">添加第三方机构</span>
            </div>
        </div>
        <div class="table_box"><div class="table_" id="tb">
            <ul class="head">
                <li class="mw300">名称</li>
                <li class="mw150">联系人</li>
                <li class="wcen">联系电话</li>
                <li class="wcen">审核状态</li>
                <li class="mw300">审核内容</li>
                <li class="mw200 wcen">审核时间</li>
                <li class="wcen">操作</li>
            </ul>
            <div class="body">
                <ul v-for="x in obj.ary" :key="x">
                    <li class="mw300">
                        <el-tooltip class="box-item" effect="dark" :content="x.name" placement="top-start" :disabled="x.name.length<17">
                            <div class="lineOne pointer">{{x.name}}</div>
                        </el-tooltip>
                    </li>
                    <li class="mw150">{{x.man}}</li>
                    <li class="wcen">{{x.mobile}}</li>
                    <li class="wcen">
                        <div :class="[globalData.verifyTypeAry2[x.verify].label,'wcen']">{{globalData.verifyTypeAry2[x.verify].text}}</div>
                    </li>
                    <li class="mw300">
                        <el-tooltip class="box-item" effect="dark" :content="x.verify_msg" placement="top-start" :disabled="x.verify_msg.length<17">
                            <div class="lineOne pointer">{{x.verify_msg}}</div>
                        </el-tooltip>
                    </li>
                    <li class="mw200 wcen">{{x.verify_time}}</li>
                    <li class="wcen">
                        <DelConfirm class="" isclass="edit_btn" :disabled="x.verify!=0" buttontype="success" @yesClick="del(x,1)" @noClick="del(x,2)" title="确认要审核通过吗？" text="审核" yes="通过" no="拒绝" />
                    </li>
                </ul>
            </div>
        </div>
        </div><Pager :value="obj.req" :init="init" />
        <el-dialog v-model="obj.drawer.design" :title="obj.drawer.designTitle" width="1000px" :close-on-click-modal="false" :destroy-on-close="true">
            <router-view @close="obj.drawer.design = false" @init="init" />
        </el-dialog>
        <el-dialog v-model="obj.drawer.staff" :title="obj.drawer.staffTitle" width="1000px" :close-on-click-modal="false" :destroy-on-close="true">
            <router-view @close="obj.drawer.staff = false" :mechanism_id="obj.drawer.mechanism_id" name="staff" />
        </el-dialog>
    </div>
</template>

<script setup>
    import { reactive,getCurrentInstance, ref,computed, toRefs,provide } from 'vue'
    import Pager from '@/components/pager.vue'
    import DelConfirm from '@/components/del_confirm.vue'
    import { ElMessageBox } from 'element-plus'
    let { proxy } = getCurrentInstance()

    let obj = reactive({
        drawer: {
            design: false,
            designTitle: "",
            staff: false,
            staffTitle: "",
            mechanism_id:0,
        },
        ary:[],
        req:{
            currentpage: 1,
            pagesize: 10,
            count: 0,
            key: "",
            state: "",
            "starttime":"",
            "endtime":"",
        }
    })

    let init = () => {
        let param = {
            ...obj.req
        }
        proxy.$ajax({
            url: '/mechanism/apply_list',
            data: param,
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                obj.ary = d.msg.list
                obj.req.count = d.msg.count
            }
        }).catch(() => { })
    }
    
    let del = (x,v) => {
        if(v==2){
            ElMessageBox.prompt('拒绝原因', '拒绝', {
                confirmButtonText: '确认',
                cancelButtonText: '取消',
                inputPlaceholder: '请输入审核原因',
                inputErrorMessage: 'Invalid Email',
            }).then(({ value }) => {
                examineverify(x.id,v,value)
            }).catch(() => {})
        }else{
            examineverify(x.id,v)
        }
    }

    const examineverify = (id,v,refuse)=>{
        console.log({ id: id , verify_state: v,refuse:refuse||''});
        // return
        proxy.$ajax({
            url: '/mechanism/apply_verify',
            data: { id: id , verify: v,verify_msg:refuse||''},
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                proxy.elMessageMixin("审核成功", 'success')
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }
</script>

<style scoped>
    ::-webkit-scrollbar { width:10px; background-color: #FFFFFF; }
    .search_select { width:100px!important; }
    #tb ul .li1 { width: 220px; }
    #tb ul .li2 { width: 80px; }
</style>